package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/activities")
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result selectList(ActivityDto activityDto){
        log.info("查询活动{}",activityDto);
        PageResult<Activity> list =activityService.selectList(activityDto);
        return Result.success(list);
    }

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        log.info("删除活动{}",id);
        activityService.deleteById(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Activity activity){
        log.info("添加活动{}",activity);
        activityService.add(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询活动{}",id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity activity){
        log.info("更新活动{}",activity);
        activityService.update(activity);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result allList(@PathVariable Integer type){
        log.info("查询所有活动");
        List<Activity> list = activityService.allList(type);
        return Result.success(list);
    }
}
